﻿using CPPEI.Coolzon.UI.Views;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace CPPEI.Coolzon.Designer.Views
{
    public partial class DesignView
    {
        /// <summary>
        /// 刷新缩放列表
        /// </summary>
        private void UpdateUI_ZoomFactorList()
        {
            ComboBoxItem selItem = this._ctlListDesignZoomFactor.SelectedItem as ComboBoxItem;
            if (selItem != null)
            {
                double selZoomValue = (double)selItem.Tag;
                if (selZoomValue == this._ctlMainFrame.ZoomFactor)
                {
                    return;
                }
            }
            bool isHit = false;
            for (int index = 0; index < this._ctlListDesignZoomFactor.Items.Count; index++)
            {
                double selZoomValue = (double)(_ctlListDesignZoomFactor.Items[index] as ComboBoxItem).Tag;
                if (Math.Abs(selZoomValue - this._ctlMainFrame.ZoomFactor) < 0.001)
                {
                    isHit = true;
                    this._ctlListDesignZoomFactor.SelectedIndex = index;
                    break;
                }
            }
            if (!isHit)
            {
                this._ctlListDesignZoomFactor.Text = (this._ctlMainFrame.ZoomFactor * 100).ToString("F1") + "%";
            }
        }
        /// <summary>
        /// 缩放列表选择事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void _ctlListDesignZoomFactor_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBoxItem selItem = this._ctlListDesignZoomFactor.SelectedItem as ComboBoxItem;
            if(selItem != null)
            {
                double selZoomValue = (double)selItem.Tag;
                this._ctlMainFrame.API_Zoom(selZoomValue, new Point(this._ctlMainFrame.ActualWidth / 2, this._ctlMainFrame.ActualHeight / 2));
            }
        }
    }
}
